package com.example.gamestore.control;

import com.example.gamestore.Bean.Admin;
import com.example.gamestore.Bean.Logs;
import com.example.gamestore.mapper.AdminMapper;
import com.example.gamestore.mapper.LogsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AdminLogControl {
    @Autowired
   private LogsMapper logsMapper;
    @GetMapping("/admin/log")
    public String getlogs(@RequestParam(name = "pn",defaultValue = "1")Integer pn, Model model){
        PageHelper.startPage(pn,5);
        List<Logs> admins = logsMapper.selectList(null);
        PageInfo<Logs> infos=new PageInfo<>(admins,5);
        model.addAttribute("pages",infos);
        return "Admin/logs";
    }

    /**
     * 删除日志
     * @param id
     * @return
     */
    @PostMapping("/admin/deletelog")
    @ResponseBody
    public String deletelogs(Integer id){
        logsMapper.deleteById(id);
        return "删除成功";
    }
}
